<?php
$gpc_get = array();
$gpc_post = array();
$gpc_cookie = array();
$gpc_files = array();
function gpcArrayConvert($a)
{
  $c = false;
  if (!get_magic_quotes_gpc()) {$c = true;}
  foreach($a as $i=>$b) {
    if($c && is_string($b)) {
      $a[$i] = addslashes($b);
    } else if(is_array($b) && count($h)>0) {
      $a[$i] = gpcArrayConvert($b);
    }
  }
  return $a;
}

  function gpcParser($get = array(), $post = array(), $cookie = array(), $files = array())
  {
    global $gpc_get;global $gpc_post; global $gpc_cookie; global $gpc_files;
  
    $gpc_get = $get;
    $gpc_post = $post;
    $gpc_cookie = $cookie;
    $gpc_files = $files;
  
    $gpc_s = array("get", "post", "cookie");
    foreach($gpc_s as $p) {
      $lod = "gpc_".strtolower($p);
      foreach($$lod as $g=>$h) {
        if (!get_magic_quotes_gpc()) {
          if(is_string($h)) {
            $h = addslashes($h);
          } else if(is_array($h) && count($h)>0) {
            $h = gpcArrayConvert($h);
          }
        }
        $$lod[$g] = $h;
      }
    }
  }

  function gpcAll($name, $value = array(), $type = "get", $type2 = 0)
  {
    global $gpc_get;
    global $gpc_post;
    global $gpc_cookie;
    global $gpc_files;
    // Abbruch bei ungueltiger Typuebergabe
    if(!in_array(strtoupper($type), array("GET", "POST", "COOKIE", "FILES"))) {
      return false;
    }
    if(strtoupper($type)=="FILES") {
      if(!isset($gpc_files[$name])) {
        return false;
      }
      if(!empty($type2)) {
        return $gpc_files[$name][$type2];
      }
      return $gpc_files[$name];
    }
    if(is_string($value) && !empty($value)) {
      $value = array($value);
    }
    if(is_string($value)) {
      $value = array();
    }
    $lod = "gpc_".strtolower($type);
    $lod = $$lod;
    if(!isset($lod[$name])) {
      return false;
    } else if($type2 === 1) {
      return true;
    }
    $lod = $lod[$name];
    if($type2===2) {
      if(empty($lod)) {
        return false;
      }
      return true;
    }
    if(count($value)>0) {
      if(in_array($lod, $value)) {
        return true;
      } else {
        return false;
      }
    }
    return $lod;
  }

  function gpcGet($name, $value = "", $type2 = 0)
  {
    return gpcAll($name, $value, "get", $type2);
  }

  function gpcPost($name, $value = "", $type2 = 0)
  {
    return gpcAll($name, $value, "post", $type2);
  }

  function gpcCookie($name, $value = "", $type2 = 0)
  {
    return gpcAll($name, $value, "cookie", $type2);
  }

  function gpcFiles($name, $zweitwahl = "")
  {
    return gpcAll($name, "", "files", $zweitwahl);
  }

  function gpcSQL($value)
  {
    if(get_magic_quotes_gpc()) {
      return mysql_real_escape_string(stripslashes($value));
    } else {
      return mysql_real_escape_string($value);
    }
  }

gpcParser($_GET, $_POST, $_COOKIE, $_FILES);
?>